#!usr/bin/env python  
#@time: 2018/01/23 
from tkinter import *
import tkinter.messagebox as messagebox

class MainFrame(Frame):
    def __init__(self,parent):
        Frame.__init__(self,parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.parent.title('测试窗口')
        self.pack(fill=BOTH, expand=1, padx=1, pady=2)
        self.nameInput = Entry(self)
        self.nameInput.pack()
        self.alertButton = Button(self, text='Hello', width=60, height=1, command=self.hello)
        self.alertButton.pack()

    def hello(self):
        name = self.nameInput.get() or 'world'
        messagebox.showinfo('Message', 'Hello, %s' % name)

def main():
    root = Tk()
    root.geometry('300x300')
    app = MainFrame(root)
    root.mainloop()

if __name__ == '__main__':
    main()